package second.greedy;

import java.util.*;

public class Solution14 {
    public int[][] reconstructQueue(int[][] people) {
        Arrays.sort(people, (o1, o2) -> {
            if (o1[0] != o2[0]) return Integer.compare(o2[0], o1[0]);
            else return Integer.compare(o1[1], o2[1]);
        });
        List<int[]> list = new ArrayList<>();
        for (int[] x : people) {
            list.add(x[1], x);
        }
        return list.toArray(new int[people.length][]);
    }
}

